/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fatecpg.songs.site.managedbeans;

import br.com.fatecpg.songs.dao.MusicianDAO;
import br.com.fatecpg.songs.dao.util.DAOException;
import br.com.fatecpg.songs.dao.util.DAOFactory;
import br.com.fatecpg.songs.entity.Musician;
import br.com.fatecpg.songs.util.FacesContextUtil;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Marcos
 */
@ManagedBean (name = "musicianSearch")
@RequestScoped
public class MusicianManagedBean {

    private Musician musician;
    private final MusicianDAO musicianDAO;

    public MusicianManagedBean() throws DAOException {
        musicianDAO = (MusicianDAO) DAOFactory.getDAO(Musician.class);
        musician = getMusicianSearch();
    }

    private Long getId() {
        if (FacesContextUtil.getParameter("idMusician") != null) {
            Long id = Long.parseLong(FacesContextUtil.getParameter("idMusician"));
            return id;
        }
        return null;
    }

    private Musician getMusicianSearch() {
        Long id = getId();
        if (id != null) {              
            musician = musicianDAO.load(id);
            return musician;
        }
        return null;
    }

    public Musician getMusician() {
        return musician;
    }

    public void setMusician(Musician musician) {
        this.musician = musician;
    }

}
